package com.mauroleon.promotail.mobile;

import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.widget.ImageView;

public class RetrieveImageTask extends AsyncTask<String, Void, Bitmap> {
   private PromotailApp app;
   private ImageView imageView;

   public RetrieveImageTask(ImageView imageView,PromotailApp app) {
      this.imageView = imageView;
      this.app = app;
   }

   @Override
   protected Bitmap doInBackground(String... args) {
      Bitmap bitmap = app.retrieveBitmap(args[0]);
      return bitmap;
   }

   @Override
   protected void onPostExecute(Bitmap bitmap) {
      if (bitmap != null) {
         imageView.setImageBitmap(bitmap);
         app.getImageCache().put((Long) imageView.getTag(), bitmap);
         imageView.setTag(null);
      }
   }
}
